<html> 
<head> 
<title> </title>
<style> 
px {font-family: "Lucida Console", Monaco }
p { font-size:100%; line-height:1.1em; }
body {xfont-style: sans-serif}
body {
color:#333; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:1em; line-height:1.3em; }
a:visited { color:#666; }
h1,h2,h3,h4,h5,h6 { color:#333; font-family:georgia, verdana, sans-serif; }
h1 { font-size:150%; page-break-before:auto;background-color: #aaaaff}
h2 { font-size:143%;color:teal; }
h3 { font-size:134%;color:blue; }
h4 { font-size:120%;color:gray; }
img { max-width: 55em}
p{ padding: 0;margin:0; }
p{ padding-right:1.4em; }
p{ padding-bottom:0.1em; }
p{ padding-top:1em; }
p{ whitespace: pre-wrap; }
h5,h6 { font-size:100% }
a.nav,a:link.nav, a:visited.nav { background-color:#FFF; color:#000; }
XXtable { border:double #000; border-collapse:collapse; }
XXtable { border-collapse:collapse; }
XXtd { border:thin solid #888; }
XXtd { border:none; }
li { margin-bottom:0.5em; }
blockquote { display:block; font-size:100%; line-height:1.1em; margin:0 0 0.5em; padding:0 2.5em; }
pre { background-color:#DDD; font-size:100%; overflow:auto; padding:1em; }
a,li span { color:#000; }
a:hover, a.nav:hover, a:hover math { background-color:#000; color:#FFF; }
#Container { margin:0 10px; text-align:center; background-color: #BBB}
#Content { border-top:none; margin:auto; padding:0.3em; text-align:left; width:100%; max-width:55em; background:#FFF}
span.webName { font-size:.5em; }
textarea#content { font-size: 1em; line-height: 1.125; }
h1#pageName { line-height:1em; margin:0.2em 0 0.2em 0; padding:0; }
.property { color:#666; font-size:100%; }
a.existingWikiWord[title]{ //border: 1px dashed #BBB; }
.byline { color:#666; font-size:1.0em; font-style:italic; margin-bottom:1em; padding-top:1px; } 
</style> 
</head>
<BODY bgcolor=#F0F0F0 text=#000000 link=#0000ff vlink=#C000C0 alink=#ff0000><A NAME=top></A>
<h5><a href="https://github.com/urbanjost/M_strings">[UP]</a></h5>
<div id="Container">
<div id="Content">
<CENTER>
<H1><HR><I>Manual Reference Pages &nbsp;-&nbsp;</I><NOBR>split2020 (3m_strings)</NOBR><HR></H1>
</CENTER>
<A name=0>

     <H3>NAME</H3>

</A>
<BLOCKQUOTE>
<B>split2020</B>(3f) - parse a string into tokens
<P>
</BLOCKQUOTE>
<A name=contents></A><H3>CONTENTS</H3></A>
<BLOCKQUOTE>
<A HREF=#1>Synopsis</A><BR>
<A HREF=#2>Description</A><BR>
<A HREF=#3>Options</A><BR>
<A HREF=#4>Examples</A><BR>
<A HREF=#5>Author</A><BR>
<A HREF=#6>License</A><BR>
<A HREF=#7>Version</A><BR>
</BLOCKQUOTE>
<A name=8>

     <H3>SYNOPSIS</H3>

</A>
<BLOCKQUOTE>
<B>TOKEN</B> <I>form</I>
<P>
<PRE>
   subroutine split2020 (string, set, tokens, separator)
   character(len=*),intent(in) :: string
   character(len=*),intent(in) :: set
   character(len=:),allocatable,intent(out) :: tokens(:)
   character(len=1),allocatable,intent(out),optional :: separator(:)
<P>
</PRE>
<B>BOUNDS</B> <I>ARRAY</I> <I>form</I>
<P>
<PRE>
   subroutine split2020 (string, set, first, last)
   character(len=*),intent(in) :: string
   character(len=*),intent(in) :: set
   integer,allocatable,intent(out) :: first(:)
   integer,allocatable,intent(out) :: last(:)
<P>
</PRE>
<B>STEP</B> <I>THROUGH</I> <I>BY</I> <I>POSITION</I> <I>form</I>
<P>
<PRE>
   subroutine split2020 (string, set, pos [, back])
   character(len=*),intent(in) :: string
   character(len=*),intent(in) :: set
   integer,intent(inout)       :: pos
   logical,intent(in),optional :: back
<P>
</PRE>
</BLOCKQUOTE>
<A name=2>

     <H3>DESCRIPTION</H3>

</A>
<BLOCKQUOTE>
Parse a string into tokens. STRING, SET, TOKENS and SEPARATOR must
all be of the same CHARACTER kind type parameter.
</BLOCKQUOTE>
<A name=3>

     <H3>OPTIONS</H3>

</A>
<BLOCKQUOTE>
<TABLE cellpadding=3>
<TR valign=top><TD width=6% nowrap>
<B>STRING</B> </TD><TD valign=bottom>
string to break into tokens
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>SET</B> </TD><TD valign=bottom>
Each character in SET is a token delimiter. A
sequence of zero or more characters in STRING delimited by
any token delimiter, or the beginning or end of STRING,
comprise a token. Thus, two consecutive token delimiters
in STRING, or a token delimiter in the first or last
character of STRING, indicate a token with zero length.
<P>
??? how about if null defaults to all whitespace characters
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>TOKENS</B> </TD><TD valign=bottom>
It is allocated with the lower bound equal to
one and the upper bound equal to the number of tokens in
STRING, and with character length equal to the length of
the longest token. The tokens in STRING are assigned by
intrinsic assignment, in the order found, to the elements
of TOKENS, in array element order.
<P>
???If input is null it still must be of size 1?
</TD></TR>
<TR valign=top><TD colspan=2>
<B>SEPARATOR</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
Each element in <B>SEPARATOR</B>(i) is assigned the value of
the ith token delimiter in STRING.
It is allocated with the lower bound equal to
one and the upper bound equal to one less than the number
of tokens in STRING, and with character length equal to
one.
<P>
???one less than? &#146;&#146; &#146; &#146;
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>FIRST</B> </TD><TD valign=bottom>
It is allocated with the lower bound equal to one and the
upper bound equal to the number of tokens in STRING. Each
element is assigned, in array element order, the starting
position of each token in STRING, in the order found. If a
token has zero length, the starting position is equal to one
if the token is at the beginning of STRING, and one greater
than the position of the preceding delimiter otherwise.
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>LAST</B> </TD><TD valign=bottom>
It is allocated with the lower bound equal to one and the
upper bound equal to the number of tokens in STRING. Each
element is assigned, in array element order, the ending
position of each token in STRING, in the order found. If
a token has zero length, the ending position is one less
than the starting position.
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>POS</B> </TD><TD valign=bottom>
If BACK is present with the value .TRUE., the value
<TABLE width=100% cellpadding=3><!-- tsb: If BACK is present with the value .TRUE., the value
 -->
<TR></TR><TR></TR>
<TR valign=top><TD colspan=2>
<B>of POS shall be in the range 0 &lt; POS</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
LEN (STRING)+1;
</TD></TR>
<TR valign=top><TD colspan=2>
<B>otherwise it shall be in the range 0</B> </TD></TR><TR valign=top><TD width=6%>&nbsp;</TD><TD>
POS LEN (STRING).
</TD></TR>
<TR></TR></TABLE>If BACK is absent or is present with the value .FALSE., POS
is assigned the position of the leftmost token delimiter in
STRING whose position is greater than POS, or if there is
no such character, it is assigned a value one greater than
the length of STRING. This identifies a token with starting
position one greater than the value of POS on invocation,
and ending position one less than the value of POS on return.
<P>
If BACK is present with the value true, POS is assigned the
position of the rightmost token delimiter in STRING whose
position is less than POS, or if there is no such character,
it is assigned the value zero. This identifies a token with
ending position one less than the value of POS on invocation,
and starting position one greater than the value of POS
on return.
<P>
When SPLIT is invoked with a value for POS of
1 &lt;= POS &lt;= <B>LEN</B>(STRING) and <B>STRING</B>(POS:POS) is not a
token delimiter present in SET, the token identified by
SPLIT does not comprise a complete token as described in the
description of the SET argument, but rather a partial token.
</TD></TR>
<TR valign=top><TD width=6% nowrap>
<B>BACK</B> </TD><TD valign=bottom>
shall be a logical scalar. It is an INTENT (IN) argument. If
POS does not appear and BACK is present with the value true,
STRING is scanned backwards for tokens starting from the
end. If POS does not appear and BACK is absent or present
with the value false, STRING is scanned forwards for tokens
starting from the beginning.
</TD></TR>
<TR></TR></TABLE></BLOCKQUOTE>
<A name=4>

     <H3>EXAMPLES</H3>

</A>
<BLOCKQUOTE>
Sample of uses
<P>
<PRE>
   program demo_sort2020
   use M_strings, only : split2020
   implicit none
   character(len=*),parameter :: gen=&#146;(*("[",g0,"]":,","))&#146;
<P>
    ! Execution of TOKEN form
    block
      character (len=:), allocatable :: string
      character (len=:), allocatable :: tokens(:)
      character (len=*),parameter :: set = " ,"
      string = &#146;first,second,third&#146;
      call split2020(string, set, tokens )
      write(*,gen)tokens
<P>
    ! assigns the value [&#146;first &#146;,&#146;second&#146;,&#146;third &#146; ]
    ! to TOKENS.
    endblock
<P>
    ! Execution of BOUNDS form
<P>
    block
      character (len=:), allocatable :: string
      character (len=*),parameter :: set = " ,"
      integer, allocatable        :: first(:), last(:)
      string =    &#146;first,second,,forth&#146;
      call split2020 (string, set, first, last)
      write(*,gen)first
      write(*,gen)last
<P>
    ! will assign the value [ 1, 7, 14, 15 ] to FIRST,
    ! and the value [ 5, 12, 13, 19 ] to LAST.
    endblock
<P>
    ! Execution of STEP form
    block
      character (len=:), allocatable :: string
      character (len=*),parameter :: set = " ,"
      integer :: p, istart, iend
      string = " one,   last  example  "
      do while (p &lt; len(string))
        istart = p + 1
        call split2020 (string, set, p)
        iend=p-1
        if(iend.gt.istart)then
           print &#146;(t3,a,1x,i0,1x,i0)&#146;, string (istart:iend),istart,iend
        endif
      enddo
    endblock
</PRE>
end program demo_sort2020
<BLOCKQUOTE>
<P>
Results:
<P>
<PRE>
   [first ],[second],[third ]
   [1],[7],[14],[15]
   [5],[12],[13],[19]
     one 2 4
     last 9 12
     example 15 21
<P>
     &gt; ??? option to skip adjacent delimiters (not return null tokens)
     &gt;     common with whitespace
     &gt; ??? quoted strings, especially CSV both " and &#146;, Fortran adjacent
     &gt;     is insert versus other rules
     &gt; ??? escape character like \\ .
     &gt; ??? multi-character delimiters like \\n, \\t,
     &gt; ??? regular expression separator
<P>
</PRE>
</BLOCKQUOTE>
</BLOCKQUOTE>
<A name=5>

     <H3>AUTHOR</H3>

</A>
<BLOCKQUOTE>
Milan Curcic, "<A HREF="mailto:milancurcic@hey.com">milancurcic@hey.com</A>"
</BLOCKQUOTE>
<A name=6>

     <H3>LICENSE</H3>

</A>
<BLOCKQUOTE>
</BLOCKQUOTE>
<A name=>

    <H4>&nbsp; &nbsp; MIT</H4>
</A>
<BLOCKQUOTE>
<P>
</BLOCKQUOTE>
<A name=7>

     <H3>VERSION</H3>

</A>
<BLOCKQUOTE>
version 0.1.0, copyright 2020, Milan Curcic
</BLOCKQUOTE>
<P><HR>
<TABLE width=100%><TR> <TD width=33%><I>Nemo Release 3.1</I></TD> <TD width=33% align=center>split2020 (3m_strings)</TD> <TD align=right width=33%><I>April 30, 2022</I></TD> </TR></TABLE><FONT SIZE=-1>Generated by <A HREF="http://www.squarebox.co.uk/download/manServer.shtml">manServer 1.08</A> from a8f9cbb9-a1d3-42ac-9333-9b0a2bd9fbe8 using man macros.</FONT>
<br><br><center><img src="images/split2020.gif"></center>
</div>
</div>
</body>
</HTML>
